{extend name='common/_container'}
{block name="content"}
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<div class="form-horizontal" id="CodeInfoForm">
			<div class="row">
				<div class="col-sm-12">
				<!-- form start -->
					<div class="form-group">
						<label class="col-sm-2 control-label">题目：</label>
						<div class="col-sm-9">
							<input type="text" autocomplete="off" id="title" value="" name="title" class="form-control" placeholder="请输入题目">
						</div>
					</div>
					<div class="form-group">
						<label class="col-sm-2 control-label">类型：</label>
						<div class="col-sm-9">
							<select lay-ignore name="type" class="form-control" id="type" style="width: 200px;float: left;">
								<option value="">请选择</option>
								<option value="1" {if condition="$info.type eq '1'"}selected{/if}>词对题</option>
								<option value="2" {if condition="$info.type eq '2'"}selected{/if}>描述题</option>
								<option value="3" {if condition="$info.type eq '3'"}selected{/if}>验证题</option>
								<option value="4" {if condition="$info.type eq '4'"}selected{/if}>终测题</option>
							</select>
						</div>
					</div>

					<div class="form-group">
						<label class="col-sm-2 control-label">图片：</label>
						<div class="col-sm-6">
							<input type="text" autocomplete="off" id="img" value="" {if condition="config('my.img_show_status') eq true"}onmousemove="showBigPic(this.value)" onmouseout="closeimg()"{/if} name="img" class="form-control" placeholder="请输入图片">
							<span class="help-block m-b-none img_process"></span>
						</div>
						<div class="col-sm-2" style="position:relative; right:30px;">
							<span id="img_upload"></span>
						</div>
					</div>
					<div id="content">
						<div class="form-group layui-form">
							<label class="col-sm-2 control-label">选项：</label>
							<div class="col-sm-9">
								<input name="options" value="" style="float: left;width: 200px;"  class="form-control" type="text"  placeholder="结果">
								<label class="col-sm-2 control-label"  style="float: left">分数：</label>
								<input name="fraction" value=""  style="float: left;width: 200px;" class="form-control" type="text"  placeholder="分数">
							</div>
						</div>
					</div>

					<input type="hidden" id="topic_id" value="{$Request.get.topic_id}" name="topic_id">
				<!-- form end -->
				</div>
			</div>
			<div class="hr-line-dashed"></div>
			<div class="row btn-group-m-t">
				<div class="col-sm-9 col-sm-offset-1">
					<button type="button" class="btn btn-primary" onclick="CodeInfoDlg.add()" id="ensure">
						<i class="fa fa-check"></i>&nbsp;确认提交
					</button>
					<button type="button" class="btn btn-danger" onclick="CodeInfoDlg.close()" id="cancel">
						<i class="fa fa-eraser"></i>&nbsp;取消
					</button>
					<button type="button" class="btn btn-warning" onclick="CodeInfoDlg.option()" id="cancel">
						<i class="fa fa-plus"></i>&nbsp;添加选项
					</button>
				</div>
			</div>
		</div>
	</div>
</div>
<script src="__PUBLIC__/static/js/upload.js" charset="utf-8"></script>
<script src="__PUBLIC__/static/js/plugins/layui/layui.js" charset="utf-8"></script>
<script>
layui.use(['form'],function(){});
uploader('img_upload','img','image',false,'','{:getUploadServerUrl()}');
var CodeInfoDlg = {
	CodeInfoData: {},
	validateFields: {
		title: {
			validators: {
				notEmpty: {
					message: '题目不能为空'
	 			},
	 		}
	 	},
	 }
}

CodeInfoDlg.collectData = function () {
	this.set('details_id').set('title').set('img').set('topic_id');
};

CodeInfoDlg.add = function () {
	 this.clearData();
	 this.collectData();
	 if (!this.validate()) {
	 	return;
	 }
	var options = new Array();
	 var fraction = new Array();
	 var els = document.getElementsByName("options");
	for (var i = 0, j = els.length; i < j; i++){
			if(els[i].value == ''){
				Feng.error( "有结果未填写！",1000);
				return;
			}
			options[i] = els[i].value;
		}
	var elsf = document.getElementsByName("fraction");
		console.log(elsf);
	for (var s = 0, f = elsf.length; s < f; s++){
		if(elsf[s].value == ''){
			Feng.error( "有结果未填写！",1000);
			return;
		}
		fraction[s] = elsf[s].value;
	}
	 var ajax = new $ax(Feng.ctxPath + "/Topic.Details/add", function (data) {
	 	if ('00' === data.status) {
	 		Feng.success(data.msg,1000);
	 		window.parent.CodeGoods.table.refresh();
	 		CodeInfoDlg.close();
	 	} else {
	 		Feng.error(data.msg + "！",1000);
		 }
	 })
	ajax.set('options',options);
	ajax.set('fraction',fraction);
	 ajax.set(this.CodeInfoData);
	 ajax.start();
};

CodeInfoDlg.option = function () {
	var html = '<div class="form-group layui-form"><label class="col-sm-2 control-label">选项：</label><div class="col-sm-9"><input name="options" value="" style="float: left;width: 200px;"  class="form-control" type="text"  placeholder="结果"><label class="col-sm-2 control-label"  style="float: left">分数：</label><input name="fraction" value=""  style="float: left;width: 200px;" class="form-control" type="text"  placeholder="分数"><button type="button" class="btn btn-danger btn-xs" title="删除"  style="margin-left: 10px" onclick="CodeInfoDlg.del(this)"><i class="fa fa-trash"></i>&nbsp;删除</button></div></div>';
	$('#content').append(html);
};
CodeInfoDlg.del = function (t) {
	$(t).parent().parent().remove();
};


</script>
<script src="__PUBLIC__/static/js/base.js" charset="utf-8"></script>
<script>

</script>
{/block}
